package com.yanqu.road.server.logic.task.condition.cricket;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.entity.task.args.CricketItemArgs;
import com.yanqu.road.entity.task.args.CricketTiTleArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;

import java.math.BigInteger;
import java.util.List;

public class CricketUpTitleCondition extends BaseCondition {


    public CricketUpTitleCondition(TaskConditionInfo taskConditionInfo, BaseTaskData baseTaskData, BigInteger value, Object initArgs) {
        super(taskConditionInfo, baseTaskData, value, initArgs);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.CricketUpTitle.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.CricketUpTitle.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(BigInteger.ZERO) > 0;
    }

    @Override
    protected void changeValue(Object object) {
        CricketTiTleArgs args = (CricketTiTleArgs) object;
        if (args != null) {
            List<BigInteger> paramList = taskConditionInfo.getParamList();
            if (args.getCricketId() == paramList.get(0).intValue()
                    && args.getTitle() >= paramList.get(2).intValue()
                    && args.getLittleTitle() >= paramList.get(3).intValue()) {
                setValue(BigInteger.ONE);
            }
        }
    }
}
